using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;

namespace TemplateWeb.DAO
{
	#region using
	using System.Data;
	using TemplateWeb.DTO;
	using TemplateWeb.Helpers;
	#endregion

	/// <summary>
	/// Data access object, which get data of HinhThucDauGia table from database
	/// </summary>
	public class HinhThucDauGiaDAO : AbstractDAO
	{
		public HinhThucDauGiaDAO(string strPath): base(strPath)
		{
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_HinhThucDauGia_SelectAll";
				base.FillDataSet(ref ds, "HinhThucDauGia");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					CommonLogging.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					CommonLogging.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public DataSet SelectByID(int id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_HinhThucDauGia_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", SqlDbType.Int, 1000, id);
				base.FillDataSet(ref ds, "HinhThucDauGia");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					CommonLogging.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					CommonLogging.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public bool Insert(HinhThucDauGiaDTO obj)
		{
			try
			{
				base.sql = "usp_HinhThucDauGia_Insert";
				base.InitializeCommand();
				base.AddParameter("@TenHinhThucDauGia", SqlDbType.NVarChar, 1000, obj.TenHinhThucDauGia);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Update(HinhThucDauGiaDTO obj)
		{
			try
			{
				base.sql = "usp_HinhThucDauGia_Update";
				base.InitializeCommand();
				base.AddParameter("@ID", SqlDbType.Int, 1000, obj.ID);
				base.AddParameter("@TenHinhThucDauGia", SqlDbType.NVarChar, 1000, obj.TenHinhThucDauGia);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Delete(int id)
		{
			try
			{
				base.sql = "usp_HinhThucDauGia_Delete";
				base.InitializeCommand();
				base.AddParameter("@ID", SqlDbType.Int, 1000, id);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

	}
}